﻿using System.Diagnostics.Contracts;
using System.Windows;

namespace OpenLS.Spreadsheet.UI
{
    public class RangeChangedEventArgs : RoutedEventArgs
    {
        private readonly Range _newRange;
        private Cell _activeCell;

        internal RangeChangedEventArgs(RoutedEvent evnt, Range newRange, Cell activeCell)
        {
            Contract.Requires(newRange != null || activeCell != null);
            Contract.Requires(evnt != null);
            _newRange = newRange;
            this._activeCell = activeCell;
            if (_newRange == null)
                _newRange = activeCell.ToRange();
            else if (activeCell == null)
                _activeCell = newRange.TopLeftCell;
            this.RoutedEvent = evnt;
        }

        public Range NewRange
        {
            get
            {
                Contract.Ensures(Contract.Result<Range>() != null);
                return _newRange;
            }
        }

        public Cell ActiveCell
        {
            get
            {
                Contract.Ensures(Contract.Result<Cell>() != null);
                return _activeCell;
            }
         
        }
    }
}